<?PHP
session_start();

require("../../conexao/ConectaMysql.class.php");
require("../../conexao/ControleAcesso.class.php");

ControleAcesso::verificaSessao();

$ACE_PRIVid =  $_SESSION['PRIVid'];
$ACE_SETid = $_SESSION['SETid'];
$ACE_FUNid = $_SESSION['FUNid'];

$conexao = new ConectaMysql();

if (isset($_POST['txtbuscar'])) {
	$txtbuscar = $_POST['txtbuscar'];

}else if (isset($_GET['txtbuscar'])) {
	$txtbuscar = $_GET['txtbuscar'];
		
}else{
	$txtbuscar = "";	
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Funcion&aacute;rio</title>
<link href="../../estrutura/css/datagrid/light/estilo.css" rel="stylesheet" type="text/css" media="screen" />
<link href="../../estrutura/css/estruturaTotal.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div class="headerModulo"><img src="../../estrutura/imagens/ico_confirmacao.png" alt="" /> &nbsp;Registros</div>
<div class="filtros" style="display: block;">
 <form id="pesquisar" method="post" action="formulario.php" name="pesquisar">
      <fieldset>
	     <span class="linha">
           <label class="preField" for="tipoServico">Localizar por:</label>
           <input id="txtbuscar" name="txtbuscar" type="text" value="<?php echo $txtbuscar; ?>"  size="40" class="caixa_texto">
           <input name="buscar" type="submit" id="buscar" value="Buscar" class="caixa_texto">
	     </span>
      </fieldset>
 </form>
</div>
<div class="datagrid_conteudo" id="datagrid_conteudo">
  <form id="datagrid_form_menus" name="datagrid_form_menus" action="formulario.php" onsubmit="return false">
    <table class="datagrid">
          
		<?php 
	 
		if ($txtbuscar != '') {
 			$txtbuscar = addslashes($txtbuscar);
			$sql_WHERE_txtbuscar = "((tb_setor.SETnome like '%$txtbuscar%') OR
			 						 (tb_setor.SETsigla like '%$txtbuscar%') OR
									 (tb_funcionario.FUNnome like '%$txtbuscar%') OR
									 (tb_funcionario.FUNsobrenome like '%$txtbuscar%') OR
									 (tb_funcionario.FUNnome like '%$txtbuscar%')) AND ";
		} else {
			
			$sql_WHERE_txtbuscar = "";
		}
			
		$queryFuncionario = "SELECT * FROM tb_funcionario 
						   INNER JOIN tb_setor ON
						   tb_setor.SETid = tb_funcionario.FUN_SETid
						   INNER JOIN tb_acesso ON
						   tb_acesso.ACE_FUNid = tb_funcionario.FUNid
						   INNER JOIN tb_privilegio ON
						   tb_privilegio.PRIVid = tb_acesso.ACE_PRIVid
						   WHERE ($sql_WHERE_txtbuscar (tb_funcionario.FUNstatus='1')) 
						   ORDER BY tb_funcionario.FUNnome, tb_funcionario.FUNsobrenome" ;
								 
			 
		$quantreg = $conexao->rowCount($queryFuncionario);	
 
		?>

        <tr>
        	<td colspan="5" class="alinCentro"><?php include("../../estrutura/paginacao.php"); ?></td>
        </tr>
        
        <tr class="header">
            <th width="24%" class=" alinCentro " style="">Funcionário</th>
            <th width="21%" class=" alinCentro " style="">Setor</th>
            <th width="21%" class=" alinCentro " style="">Privilégio</th>
            <th width="26%" class=" alinCentro " style="">Data Cadastro</th>
            <th width="8%" class=" alinCentro " style="">Op&ccedil;&otilde;es</th>
        </tr>

		<?php
	
		$result_funcionario = $conexao->executaQuery("$queryFuncionario LIMIT $inicial, $numreg");
		  
		foreach($result_funcionario as $row_funcionario){  
			$SETid       	= $row_funcionario["SETid"];
			$SETsigla       = $row_funcionario["SETsigla"];
			$FUNid			= $row_funcionario["FUNid"];
			$FUNdata		= $row_funcionario["FUNdata"];
			$FUNnome		= $row_funcionario["FUNnome"];
			$FUNsobrenome	= $row_funcionario["FUNsobrenome"];
			$PRIVdescricao	= $row_funcionario["PRIVdescricao"];
			
		?>	
            <tr id="datagrid_menus_linha_0" class="">
            <td class=" alinEsquerda "><span class="texto style57 style59 style41"><?php echo "$FUNnome $FUNsobrenome"; ?></span></td>          
            <td class=" alinEsquerda "><span class="texto style57 style59 style41"><?php echo "$SETsigla"; ?></span></td>
            <td class=" alinEsquerda "><span class="texto style57 style59 style41"><?php echo "$PRIVdescricao"; ?></span></td>
            <td class=" alinEsquerda "><span class="texto style57 style59 style41"><?php echo "$FUNdata"; ?></span></td>     
			<td class=" alinCentro ">
            <?php if(($ACE_PRIVid  == 1) || (($ACE_PRIVid  == 2) and ($ACE_SETid == $SETid)) || ($ACE_FUNid == $FUNid)){ ?>
                <a title="alterar" class="botaoDatagrid alterar" href="alterar_funcionario.php?FUNid=<?php echo "$FUNid";?>">&nbsp;</a>  
            <?php } ?>   
            </td>
            
        </tr>
		<?php } ?>  
    </table>     
  </form>
 </div> 
</body>
</html>
